/**
 * Created by 追风少年 on 2018/6/7.
 */

var Utils = {
    /**
     * 判断输入字符串是否为空或者全部都是空格
     * @param str
     * @returns {boolean} is null|undefined true else false
     */
    isNull: function(str){
        if ( str == "" ) return true;
        if ( str == undefined ) return true;
        var regu = "^[ ]+$";
        var re = new RegExp(regu);
        return re.test(str);
    },
    openInputWin: function(title, url){ // 打开默认输入窗口
        layer.open({
            title: title,
            area: ['1000px', '600px'],
            type: 2,
            content: url,
            btn: ['保存', '取消']
            , yes: function (index, layero) {
                layer.getChildFrame('body', index).find('#btnSubmit').click();
            },
            success: function (layero, index) {

            }
        });
    },
    openInfoWin: function(title, url){ // 打开默认输入窗口
        layer.open({
            title: title,
            area: ['1000px', '600px'],
            type: 2,
            content: url,
            btn: ['确认', '取消']
            , yes: function (index, layero) {
                layer.close(index);
            },
            success: function (layero, index) {

            }
        });
    },
    /**
     * 验证手机号码
     * @param mobile
     * @return is mobile return true else return false
     */
    validateMobile: function(mobile){
        if(this.isNull(mobile)){
            return false;
        }
        var myreg = /^(1+\d{10})$/;
        if(!myreg.test(mobile)){
            return false;
        }
        return true;
    },
    getCheckBoxVal:function(checkboxName){
        var chk_value =[];
        $('input[name='+checkboxName+']:checked').each(function(){
            chk_value.push($(this).val());
        });
        return chk_value;
    },
    getCheckBoxNameAndVal:function(checkboxName){
        var chk_value =[];
        $('input[name='+checkboxName+']:checked').each(function(){
            chk_value.push({
                name:$(this).attr("title"),
                value:$(this).val()
            });
        });
        return chk_value;
    }


};